/*
 *
 *
 *
 * 	(C) 2012 Mason Zhang
 *
 *
 */

#ifndef __THREAD_H__
#define __THREAD_H__

#include <windows.h>
#include <tlhelp32.h>

#define _using_thread_sync() CRITICAL_SECTION cs
#define _begin_sync() ::EnterCriticalSection(&cs)
#define _end_sync() ::LeaveCriticalSection(&cs)

extern "C" DWORD GetThreadID(HANDLE hThread,DWORD dwProcessId);

class Thread{
	private:
		DWORD Identifier;
		HANDLE Handle;
		int Status;
	public:
		Thread();
		Thread(LPTHREAD_START_ROUTINE _to_call,LPVOID Parameter);
		Thread(DWORD id,HANDLE handle,int status);
		int start(LPTHREAD_START_ROUTINE _real_call,LPVOID parameter);
		int suspend();
		int resume();
		int sleep(int time);
		int kill(int code);
		HANDLE returnHandle();
		DWORD returnIdentifier();
		int returnStatus();
		void update();
		~Thread();
};

#endif //__THREAD_H__
